<?php
$imgUrl = "";
// 允许上传的图片后缀
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["img_Url"]["name"]);
$extension = end($temp);        // 获取文件后缀名
//下面的判断为：文件类型必须为图片类，大小必须为200kb以内，后缀必须为：gif，jpeg、jpg、png
if ((($_FILES["img_Url"]["type"] == "image/gif")
        || ($_FILES["img_Url"]["type"] == "image/jpeg")
        || ($_FILES["img_Url"]["type"] == "image/jpg")
        || ($_FILES["img_Url"]["type"] == "image/pjpeg")
        || ($_FILES["img_Url"]["type"] == "image/x-png")
        || ($_FILES["img_Url"]["type"] == "image/png"))
    && ($_FILES["img_Url"]["size"] < 8192000)    // 小于 8000 kb
    && in_array($extension, $allowedExts))
{
    move_uploaded_file($_FILES["img_Url"]["tmp_name"],'../uploads/contentImg/'.$_FILES["img_Url"]["name"]);
    $imgUrl = "/back/uploads/contentImg/".$_FILES["img_Url"]["name"];
}
else{
    die("未选择文件或非法文件！");
}
//上传漫画章节封面图
$sectionImg = "";
// 允许上传的图片后缀
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["section_Img"]["name"]);
$extension = end($temp);        // 获取文件后缀名
//下面的判断为：文件类型必须为图片类，大小必须为8000kb以内，后缀必须为：gif，jpeg、jpg、png
if ((($_FILES["section_Img"]["type"] == "img/gif")
        || ($_FILES["section_Img"]["type"] == "image/jpeg")
        || ($_FILES["section_Img"]["type"] == "image/jpg")
        || ($_FILES["section_Img"]["type"] == "image/pjpeg")
        || ($_FILES["section_Img"]["type"] == "image/x-png")
        || ($_FILES["section_Img"]["type"] == "image/png"))
    && ($_FILES["section_Img"]["size"] < 8192000)    // 小于 8000 kb
    && in_array($extension, $allowedExts))
{
    move_uploaded_file($_FILES["section_Img"]["tmp_name"],'../uploads/sectionImg/'.$_FILES["section_Img"]["name"]);
    $sectionImg = "/back/uploads/sectionImg/".$_FILES["section_Img"]["name"];
}
else{
    die("未选择文件或非法文件！");
}

if($_POST["csection"]<0){
    die("章节序号非法！");
}
if(empty($_POST["section_Name"])){
    die("章节标题不能为空！");
}

$proId = $_POST["pro_id"]; // 接收漫画作品ID
$section = $_POST["csection"];   // 接收漫画章节序号
$sectionName = $_POST["section_Name"];   // 接收漫画章节名
$sql = "update content set sectionImg='$sectionImg',sectionName='$sectionName',imgUrl='$imgUrl'";
$sql .= "where proId='$proId' and section='$section'";
// 执行数据库操作，将update语句发送至数据库
// 引入打开数据库的代码
include_once dirname(__FILE__) .'../../common/conn.php';
$res = mysqli_query($con,$sql);
mysqli_close($con);
// 4. 判断执行结果，返回提示信息
if($res){
    echo "<script> {window.alert('编辑已保存');location.href='cList.php'} </script>";
    exit;
}
else{
    echo " <script> {window.alert('编辑保存失败！请稍后重试！！');location.href='cList.php'} </script>";
    exit;
}